package com.aratana.ui.fields;

import java.awt.ComponentOrientation;

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

@SuppressWarnings("serial")
public class IntegerField extends BasicField<Integer> {

	public IntegerField() {
		setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		setDocument(new PlainDocument() {

			@Override
			public void insertString(final int offs, String str, final AttributeSet a) throws BadLocationException {
				str = str.replaceAll("[^0-9]", "");
				super.insertString(offs, (getMax() > 0 && str.length() + IntegerField.this.getText().length() > getMax() ? str.substring(0, getMax() - IntegerField.this.getText().length()) : str).toUpperCase(), a);
			}
		});
	}
}
